<?php

// 获取便签内容
// GET note.get
// http://sg.io/api?note.get

namespace app\api\resource\note;
use think\Db;
use think\facade\Session;

class Get
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取便签内容';
    // 参数
    public $_param  = [];

    public function run(&$request)
    {
        $member = Session::get('member');
        $ret    = Db::name('note')->where('mid',$member['id'])->find();
        if ( is_null($ret) ) {
            $data['mid']         = $member['id'];
            $data['mobile']      = $member['mobile'];
            $data['content']     = '编辑完便签点击右上角保存';
            $data['create_time'] = time();
            $data['update_time'] = time();
            Db::name('note')->insert($data);
            return [ 200,[ 'content'=>$data['content'] ] ];
        }
        return [ 200,[ 'content'=>$ret['content'] ] ];
    }
}
